var internet = new Array();
var country = new Array();
var city = new Array();


function selectInternet(){
	$.ajax({
		url: 'https://www.supertimor.cn/media_project/index.php/externalTravel/selectInternet',
		method: 'post',
		header: 'Content-Type: application/x-www-form-urlencoded',
		async:false,
		success: function(e) {
			console.log(111,e);
			e.result.forEach(function(value, index) {
				internet.push(value.internet);
			});
			$('#internet').select({
				input: internet[0],
				title: "请选择省市",
				items: internet,
				onClose: function(d) {
					console.log(d.data.values)
					selectCountry(d.data.values);
				}
			});
		}
	})
}

function selectCountry(values){
	$.ajax({
		url: 'https://www.supertimor.cn/media_project/index.php/externalTravel/selectCountry',
		method: 'post',
		header: 'Content-Type: application/x-www-form-urlencoded',
		async:false,
		data: {
			internet: values
		},
		success: function(e) {
			console.log(222,e);
			country=new Array()
			e.result.forEach(function(value, index) {
				country.push(value.country);
			});
			$('#country').off().val('').data('weui-select',false).select({
				input: country[0],
				title: "请选择地区",
				items: country,
				onClose: function(d) {
					console.log(d.data.values)
					selectCity(values,d.data.values);
				}
			});
		}
	})
}

function selectCity(values1,values2){
	$.ajax({
		url: 'https://www.supertimor.cn/media_project/index.php/externalTravel/selectCity',
		method: 'post',
		header: 'Content-Type: application/x-www-form-urlencoded',
		async:false,
		data: {
			internet: values1,
			country: values2,
		},
		success: function(e) {
			console.log(333,e);
			city=new Array()
			e.result.forEach(function(value, index) {
				city.push(value.city);
			});
			$('#city').off().val('').data('weui-select',false).select({
				input: city[0],
				title: "请选择地区",
				items: city,
				onClose: function(d) {
					console.log(d.data.values)
				}
			});
		}
	})
}

selectInternet();
selectCountry(internet[0]);
selectCity(internet[0],country[0]);


$("#day").Spinner({min:1});


$("#submit").click(function(){
	var internet=$('#internet').val(),
		country=$('#country').val(),
		city=$("#city").val(),
		day=$('#day input').val();
	location.href=`goAbroadCalcResult.html?internet=${internet}&country=${country}&city=${city}&day=${day}`;

})
